package org.example.mymq.mqserver.core;

import java.util.Map;
import java.util.UUID;

public class Message {
    private BasicProperties basicProperties = new BasicProperties();
    private byte[] body;

    private long offsetBeg;
    private long offsetEnd;

    private byte isValid = 0x1;

//    public static Message createMessageByWithId(String routingKey,BasicProperties basicProperties,byte[] body){
//        Message message = new Message();
//        message.setMessageId(UUID.randomUUID().toString());
//        if (basicProperties != null){
//            message.setBasicProperties(basicProperties);
//        }
//        message.setRoutingKey(routingKey);
//        message.setBody(body);
//        return message;
//    }
public static Message createMessageWithId(String routingKey, BasicProperties basicProperties, byte[] body) {
    Message message = new Message();
    if (basicProperties != null) {
        message.setBasicProperties(basicProperties);
    }
    // 此处生成的 MessageId 以 M- 作为前缀.
    message.setMessageId("M-" + UUID.randomUUID());
    message.setRoutingKey(routingKey);
    message.body = body;
    // 此处是把 body 和 basicProperties 先设置出来. 他俩是 Message 的核心内容.
    // 而 offsetBeg, offsetEnd, isValid, 则是消息持久化的时候才会用到. 在把消息写入文件之前再进行设定.
    // 此处只是在内存中创建一个 Message 对象.
    return message;
}

    public String getMessageId(){
        return basicProperties.getMessageId();
    }

    public void setMessageId(String messageId){
        basicProperties.setMessageId(messageId);
    }

    public String getRoutingKey(){
        return basicProperties.getRoutingKey();
    }

    public void setRoutingKey(String routingKey){
        basicProperties.setRoutingKey(routingKey);
    }

    public int getDeliverMode(){
        return basicProperties.getDeliverMode();
    }

    public void setDeliverMode(int deliverMode){
        basicProperties.setDeliverMode(deliverMode);
    }

    public BasicProperties getBasicProperties() {
        return basicProperties;
    }

    public void setBasicProperties(BasicProperties basicProperties) {
        this.basicProperties = basicProperties;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public long getOffsetBeg() {
        return offsetBeg;
    }

    public void setOffsetBeg(long offsetBeg) {
        this.offsetBeg = offsetBeg;
    }

    public long getOffsetEnd() {
        return offsetEnd;
    }

    public void setOffsetEnd(long offsetEnd) {
        this.offsetEnd = offsetEnd;
    }

    public byte getIsValid() {
        return isValid;
    }

    public void setIsValid(byte isValid) {
        this.isValid = isValid;
    }
}
